#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QCoreApplication>
#include <QMainWindow>
#include <QDir>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    QString findPlugin(const QString &pluginName)
    {
        // 可能的插件路径列表
        QStringList possiblePaths;

        // 1. 应用程序目录下的 plugins 文件夹
        possiblePaths << QCoreApplication::applicationDirPath() + "/plugins";

        // 2. 当前工作目录
        possiblePaths << QDir::currentPath() + "/plugins";

        // 3. 用户主目录
        possiblePaths << QDir::homePath() + "/.myapp/plugins";


        qDebug() << "possiblePaths:" << possiblePaths.join(";");

        // 尝试每个路径
        foreach (const QString &path, possiblePaths) {
            QString fullPath = path + "/" + pluginName;

// 根据不同平台添加文件扩展名
#ifdef Q_OS_WIN
            if (!fullPath.endsWith(".dll"))
                fullPath += ".dll";
#elif defined(Q_OS_MAC)
            if (!fullPath.endsWith(".dylib"))
                fullPath += ".dylib";
#else
            if (!fullPath.endsWith(".so"))
                fullPath += ".so";
#endif

            if (QFile::exists(fullPath)) {
                return fullPath;
            }
        }

        return QString(); // 未找到
    }

private slots:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
